import { createStore } from 'vuex'

const store = createStore({
    state: {
        menu: JSON.parse(localStorage.getItem('menu')) || [] // 从 localStorage 恢复菜单数据
    },
    mutations: {
        setMenu(state,menuList) {
            state.menu = menuList
            localStorage.setItem('menu', JSON.stringify(menuList)) // 每次更新时存储到 localStorage
        }
    },
    getters: {
        getMenu(state) {
            return state.menu
        }
    }
})

export default store
